import {getQuestionsData,addQuestionData,updateQuestionData,delQuestionData} from '../utils/axios/index'
export const state=()=>{ 
    return{
        questions:[],
        disabledForm:""
    }
}
export const mutations={
    SET_QUESTIONS(state,data){
        state.questions=data
    },
    SET_STATUS(state,payload){
        console.log(payload);
        state.disabledForm=payload
    }

   
}
export const actions={
    // 渲染
    async randerQuestionTable({commit},$axios){
        let {data}=await getQuestionsData()
        console.log(data);
        commit("SET_QUESTIONS",data.data)
    },
    // 新增
    async handeladdQuestionData({dispatch},form){
        console.log(form);
        let r=await addQuestionData({...form,uid:1,answers:form.answers.sort().join(","),created:  Date.now()})
        console.log(r); 
        dispatch("randerQuestionTable")
    },
    // 删除
    async handeldelQuestionData({dispatch},data){
        await delQuestionData(data)
        dispatch("randerQuestionTable")

    },
    // 修改
    async handelupdateQuestionData({dispatch},form){
        await    updateQuestionData({...form,uid:1,answers:form.answers.sort().join(",")});
        dispatch("randerQuestionTable")
    }
}
export const getters={ 
    
}